package com.forenow.demo.demo16.oop;

/**
 * 对象分组：数组可以存对象
 *
 *
 */
public class ObjectAarray {
    public void getAllMessage(Student[] array){
        for (int i=0;i<array.length;i++){
            Student s=array[i];
            System.out.println(s.getName()+"---"+s.getAge());
        }
        System.out.println("---------------------------------------------");
        for (Student ss:array) {
            System.out.println(ss.getName()+"---"+ss.getAge());
        }
    }

    public Student[] getAll(){
        Student[] array=new Student[2];
        Student s1=new Student();
        //创建两个学生对象
        s1.setName("catty");
        s1.setAge(15);
        Student s2=new Student();
        s2.setName("bob");
        s2.setAge(17);
        //将对象保存到数组当中
        array[0]=s1;
        array[1]=s2;
        return array;
    }
    public static void main(String[] args) {
        //创建一个Student类型的数组容器

        //调用ObjectAarray的方法输出
       ObjectAarray objectAarray=new ObjectAarray();
       Student[] sss=objectAarray.getAll();
        for (Student stu:sss) {
            System.out.println(stu.getName()+"---"+stu.getAge());
        }
    }
}
